using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using WCF = System.Web.Configuration.WebConfigurationManager;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DanhMucPhu_Data
/// </summary>
public class DanhMucPhu_Data
{

    public void insert(DanhMucPhu_Info DM)
    {
        string connectionString = WCF.ConnectionStrings["gets_SPDG"].ConnectionString;
        SqlConnection connection = new SqlConnection(connectionString);
        if (connection.State == ConnectionState.Open)
            connection.Close();
        connection.Open();
        //SqlDataAdapter adapter = new SqlDataAdapter();
        try
        {
            SqlCommand Command = new SqlCommand();
            Command.CommandText = "sp_ThemDanhMucPhu";
            Command.Connection = connection;
            Command.CommandType = CommandType.StoredProcedure;
            Command.Parameters.Add("@MaDanhMucChinh", SqlDbType.Int, 4);
            Command.Parameters["@MaDanhMucChinh"].Value = DM.MaDanhMucChinh;
            Command.Parameters.Add("@Ten", SqlDbType.NVarChar, 50);
            Command.Parameters["@Ten"].Value = DM.Ten;
            Command.Parameters.Add("@SoSanPhamDangDaugia", SqlDbType.Int, 4);
            Command.Parameters["@SoSanPhamDangDauGia"].Value = DM.SoSanPhamDangDauGia;
            //adapter.SelectCommand = Command;
            SqlDataReader reader;
            reader = Command.ExecuteReader();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }

    public void update(DanhMucPhu_Info DM)
    {
        string connectionString = WCF.ConnectionStrings["gets_SPDG"].ConnectionString;
        SqlConnection connection = new SqlConnection(connectionString);
        if (connection.State == ConnectionState.Open)
            connection.Close();
        connection.Open();
        SqlDataAdapter adapter = new SqlDataAdapter();
        try
        {
            SqlCommand Command = new SqlCommand();
            Command.CommandText = "CapNhatDanhMucPhu";
            Command.Connection = connection;
            Command.CommandType = CommandType.StoredProcedure;
            Command.Parameters.Add("@MaDanhMucChinh", SqlDbType.Int, 4);
            Command.Parameters["@MaDanhMucChinh"].Value = DM.MaDanhMucChinh;
            Command.Parameters.Add("@Ten", SqlDbType.NVarChar, 50);
            Command.Parameters["@Ten"].Value = DM.Ten;
            Command.Parameters.Add("@SoSanPhamDangDaugia", SqlDbType.Int, 4);
            Command.Parameters["@SoSanPhamDangDauGia"].Value = DM.SoSanPhamDangDauGia;
            adapter.SelectCommand = Command;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }

    public void delete(DanhMucPhu_Info DM)
    {
        string connectionString = WCF.ConnectionStrings["gets_SPDG"].ConnectionString;
        SqlConnection connection = new SqlConnection(connectionString);
        if (connection.State == ConnectionState.Open)
            connection.Close();
        connection.Open();
        SqlDataAdapter adapter = new SqlDataAdapter();
        try
        {
            SqlCommand Command = new SqlCommand();
            Command.CommandText = "XoaDanhMucPhu";
            Command.Connection = connection;
            Command.CommandType = CommandType.StoredProcedure;
            Command.Parameters.Add("@Ma", SqlDbType.Int, 4);
            Command.Parameters["@Ma"].Value = DM.Ma;
            adapter.SelectCommand = Command;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }

	public DanhMucPhu_Data()
	{
		//
		// TODO: Add constructor logic here
		//
	}
}
